package com.fenghongzhang.module_home.sqlite_provider

import android.content.ContentProvider
import android.content.ContentValues
import android.database.Cursor
import android.database.sqlite.SQLiteDatabase
import android.net.Uri


class MyProvider : ContentProvider() {
    private var myHelper: MyHelper? = null
    private var db: SQLiteDatabase? = null
    override fun delete(uri: Uri, selection: String?, selectionArgs: Array<String>?): Int {
        TODO("Implement this to handle requests to delete one or more rows")
    }

    override fun getType(uri: Uri): String? {
        TODO(
            "Implement this to handle requests for the MIME type of the data" +
                    "at the given URI"
        )
    }

    override fun insert(uri: Uri, values: ContentValues?): Uri? {
       db?.insert("student",null,values);
        return uri;
    }

    override fun onCreate(): Boolean {
        myHelper= MyHelper(getContext());
        db= myHelper?.getWritableDatabase();
        if(db==null){
            return false;
        }else{
            return true;
        }
    }

    override fun query(
        uri: Uri, projection: Array<String>?, selection: String?,
        selectionArgs: Array<String>?, sortOrder: String?
    ): Cursor? {
        return  db?.query("student",projection,selection,selectionArgs,null,null,sortOrder);

    }

    override fun update(
        uri: Uri, values: ContentValues?, selection: String?,
        selectionArgs: Array<String>?
    ): Int {
        TODO("Implement this to handle requests to update one or more rows.")
    }
}